<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="系部" prop="college">
        <el-input
          v-model="queryParams.college"
          placeholder="请输入系部"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <!-- <el-form-item label="推荐项" prop="researchtopic">
        <el-select
          v-model="queryParams.researchtopic"
          placeholder="推荐项"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in recommendOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
 -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
    <!--  <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="goApply"
          v-hasPermi="['eqxm:team:add']"
        >录入排名</el-button>
      </el-col> -->
    
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="teamList" @selection-change="handleSelectionChange">
			<el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="团队名称" align="center" prop="teamName" />
      <el-table-column label="系部" align="center" prop="college" />
      <el-table-column label="调研主题" :formatter="researchtopicFormat" align="center" prop="researchtopic" />
	  <el-table-column label="实打/应打" align="center" prop="clockCount" >
		  <template slot-scope="scope">
			  <span>{{scope.row.clockCount}}/{{scope.row.shouldClockCount}}</span>
			</template>
		  </el-table-column>
     <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['eqxm:team:edit']"
          >查看资料</el-button>
   
        </template>
      </el-table-column>
	  <el-table-column label="状态" align="center" prop="advancedStatus" :formatter="advancedStatusFormat"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改团队对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="系部" prop="college">
          <el-input v-model="form.college" placeholder="请输入系部" />
        </el-form-item>
        <el-form-item label="调研主题" prop="researchtopic">
          <el-input v-model="form.researchtopic" placeholder="请输入调研主题" />
        </el-form-item>
        <el-form-item label="是否重点" prop="isimportant">
          <el-input v-model="form.isimportant" placeholder="请输入是否重点" />
        </el-form-item>
        <el-form-item label="呈现形式" prop="presentation">
          <el-input v-model="form.presentation" placeholder="请输入呈现形式" />
        </el-form-item>
        <el-form-item label="呈现形式详情" prop="presentationdetail">
          <el-input v-model="form.presentationdetail" placeholder="请输入呈现形式详情" />
        </el-form-item>
        <el-form-item label="交通费" prop="transportation">
          <el-input v-model="form.transportation" placeholder="请输入交通费" />
        </el-form-item>
        <el-form-item label="住宿费" prop="accommodation">
          <el-input v-model="form.accommodation" placeholder="请输入住宿费" />
        </el-form-item>
        <el-form-item label="宣传费" prop="publicity">
          <el-input v-model="form.publicity" placeholder="请输入宣传费" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTeam, getTeam, delTeam, addTeam, updateTeam, exportTeam } from "@/api/eqxm/team";
import { listTeamStudent, getTeamStudent, delTeamStudent, addTeamStudent, updateTeamStudent, exportTeamStudent,listAdvanced } from "@/api/eqxm/teamStudent";

import CommonUtils from "@/utils/CommonUtils";
export default {
  name: "Team",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 团队表格数据
      teamList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        college: null,
        researchtopic: null,
        isimportant: null,
        presentation: null,
        presentationdetail: null,
        transportation: null,
        accommodation: null,
        publicity: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      recommendOptions:[],
			 advancedStatusOptions:[]
    };
  },
  created() {
	this.getDicts("teamstatus").then(response => {
	  this.teamstatus = response.data;
	});
	this.getDicts("researchtopic").then(response => {
	  this.researchtopics = response.data;
	});
	this.getDicts("isimportant").then(response => {
	  this.isimportants = response.data;
	});	
	this.getDicts("advancedStatus").then(response => {
	  this.advancedStatusOptions = response.data;
	});	
	this.getList();
	this.getDicts("recommend").then(response => {
		this.recommendOptions = response.data;
	});
  },
  methods: {
	  statusFormat(row, column) {
	    return this.selectDictLabel(this.teamstatus, row.status);
	  },
	  isimportantFormat(row, column) {
	    return this.selectDictLabel(this.isimportants, row.isimportant);
	  },
	  researchtopicFormat(row, column) {
		if( row.researchtopic==null){
			return "";
		}  
	    return this.selectDictLabel(this.researchtopics, row.researchtopic);
	  },
	  recommendFormat(row, column) {
	    return this.selectDictLabel(this.recommendOptions, row.recommend);
	  },
		advancedStatusFormat(row, column) {
		  return this.selectDictLabel(this.advancedStatusOptions, row.advancedStatus);
		},
    /** 查询团队列表 */
    getList() {
      this.loading = true;
      listAdvanced(this.queryParams).then(response => {
        this.teamList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        delFlag: null,
        college: null,
        createBy: null,
        researchtopic: null,
        isimportant: null,
        createTime: null,
        presentation: null,
        updateBy: null,
        presentationdetail: null,
        updateTime: null,
        transportation: null,
        accommodation: null,
        publicity: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
     //清空store的项目信息
     let teamInfo = {
       id:''
     }
     CommonUtils.setCurTeamInfo(teamInfo)
     const vm = this
     vm.$router.push({  //核心语句
       path:'/team/teamManage',//跳转的路径
       query: {type:0}
     })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
    
      const vm = this
      vm.$router.push({  //核心语句
        path:'/advanced/look/'+row.id//跳转的路径
      })
    },
    upload(row) {
      this.reset();
      let teamInfo = {
        id:row.id
      }
      CommonUtils.setCurTeamInfo(teamInfo)
      const vm = this
      vm.$router.push({  //核心语句
        path:'/team/upload',//跳转的路径
        query: {type:0}
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTeam(this.form).then(response => {
              if(response.code==200){
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              }
            });
          } else {
            addTeam(this.form).then(response => {
              if(response.code==200){
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除团队编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delTeam(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有团队数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportTeam(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    },
    recommendTeam(){
      let teamInfo = {
        id:''
      }
      CommonUtils.setCurTeamInfo(teamInfo)
      const vm = this
      vm.$router.push({  //核心语句
        path:'/schoolmatch/recommendTeam'//跳转的路径
      })
    },
    judge(){
      let teamInfo = {
        id:''
      }
      CommonUtils.setCurTeamInfo(teamInfo)
      const vm = this
      vm.$router.push({  //核心语句
        path:'/schoolmatch/judge'//跳转的路径
      })
    },
    review(){
      let teamInfo = {
        id:''
      }
      CommonUtils.setCurTeamInfo(teamInfo)
      const vm = this
      vm.$router.push({  //核心语句
        path:'/schoolmatch/review'//跳转的路径
      })
    },
	collegeScore(){
      let teamInfo = {
        id:''
      }
      CommonUtils.setCurTeamInfo(teamInfo)
      const vm = this
      vm.$router.push({  //核心语句
        path:'/schoolmatch/collegeScore'//跳转的路径
      })
    },
	goApply(){
      const vm = this
      vm.$router.push({  //核心语句
        path:'/advanced/apply'//跳转的路径
      })
    },
  }
};
</script>
